/**
 * Created with IntelliJ IDEA.
 * User: csavard
 * Date: 13-08-28
 * Time: 13:45
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function () {
    $('#generate-button').bind('touchstart click', function (e) {
        e.preventDefault();
        generate();
    });

    $.ajaxSetup({ cache: false });
    setInterval(refresh, 250);
});

function generate() {
    $('#pleaseWaitDialog').modal({
        backdrop: 'static',
        keyboard: false
    });
    $.getJSON('chep/generate').always(function () {
        $('#pleaseWaitDialog').modal('hide');
    });
}

/**
 * Rafraîchit le status et l'état des composant selon l'état du serveur d'interface.
 */
function refresh() {
    $.getJSON('chep/get.result.file.name',function (data) {
            var downloadLink = $('#downloadLink');
            if (data.fileName !== null && data.fileName.length > 0) {
                downloadLink.text("Téléchargez: " + data.fileName);
                downloadLink.fadeIn(2000);
            } else {
                downloadLink.fadeOut();
            }
        }
    ).fail(function (xhr, ajaxOptions, thrownError) {
            console.info(xhr.status);
            console.info(thrownError.message);
        });
}

